extends TileMap

onready var menu = get_parent().get_node("UI/Menu")

func _input(event: InputEvent) -> void:
	if event is InputEventMouseButton && event.button_index == BUTTON_LEFT && event.is_pressed():
		#需要再选路的状态下才可以移动	
		if Game.game_state == Game.GAMESTATE.SELECTMOVEPATH :
			Game.mouse_pos = world_to_map(get_global_mouse_position())
			if Game.canMovePathArr.has(Game.mouse_pos) and Game.mouse_pos != Game.current_player.heroSpawn:
				#判断点击当前位置有没有障碍物，英雄和敌人
				if Utils.getActorByPath(Game.mouse_pos):
					return
				Game.current_player.start_move()
			else :
				Game.current_player.cleanPath()
		
		if Game.game_state == Game.GAMESTATE.SELECTATTACKPATH :
			Game.mouse_pos = world_to_map(get_global_mouse_position())
			if Game.attackPathArr.has(Game.mouse_pos) and Game.mouse_pos != Game.current_player.heroSpawn:
				#检测当前点击坐标是否存在物体(敌人，英雄，障碍物)
				if Utils.getActorByPath(Game.mouse_pos) and Utils.getActorByPath(Game.mouse_pos).type == Game.ACTORTYPE.ENEMY:
					Game.current_player.enter_fight_scene()
			else :
				Game.current_player.cleanPath()
		
		if Game.game_state == Game.GAMESTATE.SHOWMENU:
			#判断鼠标是否在menu区域里面
			if !menu.check_area(get_global_mouse_position()):
				menu.ctrl_menu(false)
				Game.game_state = Game.GAMESTATE.IDLE

